<template>
  <el-button
    :loading="btnloading"
    type="primary">
    导出
  </el-button>
</template>
<script>
    import {exportMajor,exportContact,exportHome,exportWorking,exportSchool,exportUserInfo,exportUserReward,exportUserContract,exportUserCommunicate,exportUserTrain} from '@/api/company'
    import XLSX from "xlsx";
    const defaultGtForm = {
      "userId": null,						//员工id
      "communicateUserId":"",				//沟通者id
      "content": "",						//沟通内容
      "result": "",						//沟通结果
      "communicateTime": "",	//沟通时间
      "nextCommunicateTime": ""	//下次沟通时间
    }
    export default {
        name: "exportPop",
        data(){
            return {
              btnloading:false,
            }
        },
        computed: {

        },
        components : {

        },
        created() {

        },
        methods:{
          //下载excle
          downloadExcel(type,params){
            let fn
            switch (type){
              case 'exportUserInfo':
                fn = exportUserInfo;
                break;
              case 'exportUserReward':
                fn = exportUserReward;
                break;
              case 'exportUserContract':
                fn = exportUserContract;
                break
              case 'exportUserCommunicate':
                fn = exportUserCommunicate;
                break;
              case 'exportUserTrain':
                fn = exportUserTrain;
                break;
              case 'exportSchool':
                fn = exportSchool;
                break;
              case 'exportWorking':
                fn = exportWorking;
                break;
              case 'exportMajor':
                fn = exportMajor;
                break;
              case 'exportContact':
                fn = exportContact;
                break;
              case 'exportHome':
                fn = exportHome;
                break;
            }
            this.btnloading = true;
            let pa = JSON.parse(JSON.stringify(params))
            delete pa.pageNum;
            delete pa.pageSize
            fn(pa).then((res)=>{
              this.btnloading = false
              require.ensure([], () => {
                const { export_json_to_excel } = require('sheet/Export2Excel');
                const tHeader = res.title;
                const filterVal = res.columns;
                const list = res.list;
                const data = this.formatJson(filterVal, list);
                export_json_to_excel(tHeader, data, res.fileName);
              })
            }).catch(()=>{
              this.btnloading = false
            })
          },

          //下载表格数据格式化
          formatJson(filterVal, jsonData) {
            return jsonData.map(v => filterVal.map(j => v[j]))
          },

        },
    }
</script>

<style scoped lang="scss">

</style>
